<template>
  <div id="big">
    <el-container>
      <el-aside>
        <el-menu
          :default-active="defaultActive"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/home">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-submenu v-for="item in getUserInfo.menus" :key="item.id" :index="item.id.toString()">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item v-for="menu in item.children" :key="menu.id" :index="menu.url">{{menu.title}}</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header height="80px">
          <img class="img" src="../assets/images/3.png" alt="">
          <div class="admin">
            <div style="fontSize:18px">用户名：{{$store.getters.getUserInfo.username}}</div>
            <el-button class="btn" @click="logout" type="danger" size="mini">退出</el-button>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  data() {
    return {
      defaultActive: "/home"
    };
  },
  computed:{
    ...mapGetters(['getUserInfo'])
  },
  mounted() {
    this.defaultActive = this.$route.path;
  },
  methods: {
    logout(){
      sessionStorage.removeItem('userinfo')
      this.$router.push('/login')
    }
  },
};
</script>

<style scoped>
#big{
  background: #ccc;
}
.el-menu {
  padding: 0;
  min-height: 90vh;
  width: 250px;
}
.el-main {
  margin-left: -50px;
  background: #ccc;
}
.el-aside {
  width: 250px;
}
.btn {
  margin-top: 10px;
}
.admin{
  float: right;
  margin-top: 10px
}
.el-header{
  background: orange;
  margin-left: -50px;
}
.img{
  margin-top: 10px
}
</style>
